<!-- 卡片集合 -->
<template>
  <div class="container">
    <div class="card">
      <input type="radio" name="select" id="slide_1" :checked="!isChange">

      <!-- <div class="inner_part">
        <div class="player-container pr-30">
              <vue-core-video-player :autoplay="false" src="http://cloud.kingyin.club/vio/doc/IMG_0901.MP4">
              </vue-core-video-player>
            </div>
    </div> -->

      <div class="inner_part">
        <div class="content content_1">
          {{name}}
          <div class="title">@{{comments[prentCurrent].username[currentIndex]}}</div>
          <div class="row">

            <div class="col-11">
              <el-input class="mb-20" v-if="showInput" v-model="input" placeholder="记录此刻~"></el-input>
            </div>
            <div class="col-1 mt-10">
              <a v-if="showInput" class="ml-10" href="javascript:void(0)" @click="showInput = false">取消</a>
            </div>
          </div>
          <div v-if="!showInput" class="text">

            <vue-typer :text="comments[prentCurrent].comment[currentIndex]" erase-style='backspace' :erase-delay='70'
              :type-delay='120'></vue-typer>
          </div>
          来自：{{comments[prentCurrent].date[currentIndex]}}
          <button @click="send()">{{showInput?'发送':'发起共鸣'}}</button>
          <a class="ml-5" href="javascript:void(0)">♥{{$commons.formatNumber(comments[prentCurrent].like[currentIndex])}}</a>
          <div class="mt-10">
            <a class="mr-10" href="javascript:void(0)" @click="next(-1)">上一条</a>
            
            <a class="mr-15" href="javascript:void(0)" @click="next(1)">下一条</a>
            <a href="javascript:void(0)" >复制媒体链接</a>
          </div>
          <!-- <a href="javascript:void(0)">举报</a> -->
        </div>
      </div>

    </div>
  </div>
</template>

<script>
  //这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
  //例如：import 《组件名称》 from '《组件路径》';
  import bus from '../../utils/bus.js'
  export default {
    //import引入的组件需要注入到对象中才能使用
    components: {},
    props: ['comments', 'name'],
    data() {
      //这里存放数据
      return {
        btnTxt: this.showInput ? '发送' : '共鸣',
        showInput: false,
        input: '',
        currentIndex: 0,
        name:'',
        path:'',
        prentCurrent: 0,
        isChange: false,
      };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
      getName() {
        var ns = this.path.split('/');
        return ns[ns.length-1];
      },
      loadComment() {
        // 监听事件
        bus.$on('loadComment', res => {
          if (res.name == this.name) {
            this.prentCurrent = res.data.idx;
            this.path = res.data.path;
            this.name = this.getName();
          }

        })
      },
      async next(val) {
        this.isChange = true;
        await this.sleep(500)
        this.isChange = false;
        this.currentIndex += val;
        if (this.currentIndex == this.comments[this.prentCurrent].username.length) {
          this.currentIndex = 0;
        } else if (this.currentIndex == -1) {
          this.currentIndex = this.comments[this.prentCurrent].username.length - 1;
        }
      },
      send() {
        if (this.showInput) {
          // 发送

        }
        this.showInput = !this.showInput;
      },
      sleep(ms) {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve()
          }, ms)
        })
      },
      async toNext() {
        if (this.showInput) {
          return;
        }
        await this.next(1);
      }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {

    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {
      this.loadComment();
      setInterval(this.toNext, 7000);
    },
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {
      //取消监听'getCheckboxStatus'事件
      bus.$off('loadComment');
    }, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  }

</script>
<style scoped>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  html,
  body {
    height: 100vh;
    font-family: 'Open Sans', sans-serif;
  }

  body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #cecece;
  }

  .container {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .card {
    position: absolute;
    height: 350px;
    width: 100%;
    max-width: 850px;
    margin: auto;
    background: #ffffff;
    border-radius: 25px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
  }

  .card .inner_part {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0 0 30px;
    height: 350px;
    position: absolute;
  }

  #slideImg:checked~.inner_part {
    padding: 0;
    transition: .1s ease-in;
  }

  .inner_part .img {
    height: 260px;
    width: 260px;
    overflow: hidden;
    flex-shrink: 0;
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.2);
  }

  #slideImg:checked~.inner_part .img {
    height: 350px;
    width: 850px;
    z-index: 99;
    transition: .3s .2s ease-in;
  }

  .img img {
    height: 100%;
    width: 100%;
    cursor: pointer;
    opacity: 0;
    transition: .6s;
  }

  #slide_1:checked~.inner_part .img_1,
  #slide_2:checked~.inner_part .img_2,
  #slide_3:checked~.inner_part .img_3 {
    opacity: 1;
    transition-delay: .2s;
  }

  .content {
    padding: 0 20px 0 35px;
    width: 530px;
    margin-left: 50px;
    opacity: 0;
    transition: .6s;
  }

  #slideImg:checked~.inner_part .content {
    display: none;
  }

  #slide_1:checked~.inner_part .content_1,
  #slide_2:checked~.inner_part .content_2,
  #slide_3:checked~.inner_part .content_3 {
    opacity: 1;
    margin-left: 0;
    z-index: 100;
    transition-delay: .3s;
  }

  .content .title {
    font-size: 30px;
    font-weight: 700;
    color: #0d0925;
    margin: 0 0 20px 0;
  }

  .content .text {
    font-size: 19px;
    color: #4e4a67;
    margin: 0 auto 30px auto;
    line-height: 1.5em;
    text-align: justify;
  }

  .content button {
    padding: 15px 20px;
    border: none;
    font-size: 16px;
    color: #fff0e6;
    font-weight: 600;
    letter-spacing: 1px;
    border-radius: 50px;
    cursor: pointer;
    outline: none;
    background: #000000;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.2);
    float: right;
  }

  .content button:hover {
    background: #cecece;
    color: #000000;
  }

  .slider {
    position: absolute;
    bottom: 25px;
    left: 55%;
    transform: translateX(-50%);
    z-index: 1;
  }

  #slideImg:checked~.slider {
    display: none;
  }

  .slider .slide {
    position: relative;
    height: 10px;
    width: 50px;
    background: #d9d9d9;
    border-radius: 5px;
    display: inline-flex;
    margin: 0 3px;
    cursor: pointer;
  }


  .slider .slide:before {
    position: absolute;
    content: '';
    top: 0;
    left: 0;
    height: 100%;
    width: -100%;
    background: #000000;
    ;
    border-radius: 10px;
    transform: scaleX(0);
    transition: transform .6s;
    transform-origin: left;
  }

  #slide_1:checked~.slider .slide_1:before,
  #slide_2:checked~.slider .slide_2:before,
  #slide_3:checked~.slider .slide_3:before {
    transform: scaleX(1);
    width: 100%;
  }

  input {
    display: none;
  }

</style>
